let app = getApp()
Component({
    properties: {
        pageIndex:Number,
        distribution_id:Number,
        layer_num:Number
      },
      data:{
        info: [],
        pageHeight: "auto",
        pageIndex: 0,
        page:1,
        requestUrl: "",
        level: 0,
        nodata:true,
        accountType: {
          arr:['微信','支付宝','银行卡']
       }
      },
      pageLifetimes: {
        show: function () {
          var page=this.data.pageIndex
          var pagetitle=''; 
          switch(page){
            case 0:
              if(this.data.distribution_id==wx.getStorageSync('distribution_id')){
                pagetitle='我的团队';
              }else{
                pagetitle=wx.getStorageSync('distribution_teamname')+'的团队';
              }
              this.getTeamList();
              break;
            case 1:
              pagetitle='我的客户';
              this.getCustomerList();
              break;
            case 2:
              pagetitle='佣金明细';
              this.getCommissionList();
              break;
            case 4:
              pagetitle='提现明细';
              this.getWithdrawList();
              break;
           case 5:
              pagetitle='我的银行卡';
              this.getWithdrawMethodList();
              break;
          }
          wx.setNavigationBarTitle({
            title:pagetitle
          })
        }
      },
    lifetimes: {
        attached: function () {
          
       }
      },
    methods: {
      teaminfo:function(e){
        var layer_type=wx.getStorageSync('distribution').layer_type
        if(this.data.layer_num==layer_type){
          wx.showToast({
            icon: "none",
            title: "最多可查看".concat(layer_type, "层关系！")
          })
        }else{
          wx.setStorageSync('distribution_teamname',e.currentTarget.dataset.name)
          var layer_num=parseInt(this.data.layer_num)+1;
          wx.navigateTo({
            url: '/yb_shopv2/native/all/index?type=page_IntegralDistributionList&index=0&distribution_id='+e.currentTarget.dataset.id+'&layer_num='+layer_num
          })
        }
      },
      getTeamList:function(){
        var that=this
        wx.request({
          url: app.globalData.siteroot,
          data: {
            do:'Distribution_getTeamList',
            staff_id:wx.getStorageSync('staff_bind_id'),
            distribution_id:that.data.distribution_id,
            page:that.data.page
          },
          success: function(res) {
            if(res.data.data.length>0){
                that.setData({
                  nodata:false,
                  info:res.data.data
                })
            }else{
              that.setData({
                nodata:true
              })
            }
          }
        })
      },getCustomerList:function(){
        var that=this
        wx.request({
          url: app.globalData.siteroot,
          data: {
            do:'Distribution_getCustomerList',
            staff_id:wx.getStorageSync('staff_bind_id'),
            distribution_id:wx.getStorageSync('distribution_id'),
            page:that.data.page
          },
          success: function(res) {
            if(res.data.data.length>0){
                that.setData({
                  nodata:false,
                  info:res.data.data
                })
            }else{
              that.setData({
                nodata:true
              })
            }
          }
        })
      },getCommissionList:function(){
        var that=this
        wx.request({
          url: app.globalData.siteroot,
          data: {
            do:'Distribution_getCommissionList',
            staff_id:wx.getStorageSync('staff_bind_id'),
            distribution_id:that.data.distribution_id,
            page:that.data.page
          },
          success: function(res) {
            if(res.data.data.length>0){
                that.setData({
                  nodata:false,
                  info:res.data.data
                })
            }else{
              that.setData({
                nodata:true
              })
            }
          }
        })
      },getWithdrawList:function(){
        var that=this
        wx.request({
          url: app.globalData.siteroot,
          data: {
            do:'Distribution_getWithdrawList',
            staff_id:wx.getStorageSync('staff_bind_id'),
            distribution_id:wx.getStorageSync('distribution_id'),
            page:that.data.page
          },
          success: function(res) {
            if(res.data.data.length>0){
                that.setData({
                  nodata:false,
                  info:res.data.data
                })
            }else{
              that.setData({
                nodata:true
              })
            }
          }
        })
      },getWithdrawMethodList:function(){
        var that=this
        wx.request({
          url: app.globalData.siteroot,
          data: {
            do:'Distribution_getWithdrawMethodList',
            staff_id:wx.getStorageSync('staff_bind_id'),
            distribution_id:wx.getStorageSync('distribution_id'),
            page:that.data.page
          },
          success: function(res) {
            if(res.data.data.length>0){
                that.setData({
                  nodata:false,
                  info:res.data.data
                })
            }else{
              that.setData({
                nodata:true
              })
            }
          }
        })
      },delcard:function(e){
        const id =e.currentTarget.dataset.id;
        var that=this
        wx.showModal({
          title: '提示',
          content: '确认要删除此账户吗？',
          showCancel: true,
          cancelText:"取消",
          confirmText:"确定",
          success: function (res) {
            if (res.cancel) {
           } else{
            wx.request({
              url: app.globalData.siteroot,
              data: {
                do:'Distribution_delWithdrawMethod',
                staff_id:wx.getStorageSync('staff_bind_id'),
                id:id
              },
              success: function(res) {
                      that.getWithdrawMethodList();
              }
            })
           
           }
           },
           fail: function (res) { },
           complete: function (res) { }
      })
      },addCardBtn:function(){
        wx.navigateTo({
          url: '/yb_shopv2/native/all/index?type=page_addCard&page_type=1'
        })
      }
    }
});
